package com.sunny.ynhz.utils;

import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.view.View;
import android.widget.Button;

/**
 * Created by hhh on 2017/11/27.
 */

public class AlertUtils {

    private AlertDialog alertDialog;

    public interface IClickButton{
        void ensure();
        void cancel();
    }
    private String title="提示";
    private String content;

    public void setMsg(String msg) {
        this.msg = msg;
    }

    private String msg;
    public void setTitle(String title) {
        this.title = title;
    }
    public void setContent(String content) {
        this.content = content;
    }

    public void setEnsureButton(String ensureButton) {
        this.ensureButton = ensureButton;
    }

    public void setNegativeButton(String negativeButton) {
        this.negativeButton = negativeButton;
    }
    private String ensureButton="是";
    private String negativeButton="否";
    public void displayDiago(Context context, final IClickButton iClickButton){
        alertDialog = new AlertDialog.Builder(context)
                .setTitle(title)
                .setMessage(msg)
                .setPositiveButton(ensureButton,null)
                .setNegativeButton(negativeButton,null)
                .create();
         alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
             @Override
             public void onShow(DialogInterface dialogInterface) {
                 Button positive = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
                 Button negative = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
                 positive.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                         if(iClickButton!=null){
                             iClickButton.ensure();
                         }

                     }
                 });
                 negative.setOnClickListener(new View.OnClickListener() {
                     @Override
                     public void onClick(View view) {
                         if(iClickButton!=null){
                             iClickButton.cancel();
                             alertDialog.dismiss();
                         }
                     }
                 });

             }
         });
        alertDialog.setCanceledOnTouchOutside(false);
        alertDialog.show();
    }
    public void closeDialog(){
        alertDialog.dismiss();
    }


}
